<?php
	require_once '../lib/sql.utils.php';
	
	$bookId = $_POST['bookId'];
	$sql_util = new SqlUtils();
	$result = $sql_util -> getRows('SELECT * FROM books WHERE bookId = '.$bookId);
?>
<div class="menu">
		Quản lý Đầu sách > Sửa thông tin sách
	</div>
<form id="myForm" name="myForm" method="post" enctype="multipart/form-data" action="service/process_edit_book.php">
	<input type="hidden" name="isImage" value="<?php echo $result[0]['bookImage']; ?>" />
	<input type="hidden" name="id" value="<?php echo $result[0]['bookId']; ?>" />
	<label for="name">Tên Sách :</label>
	<input type="text" id="name" name="name" value="<?php echo $result[0]['bookName']; ?>" />
	<span id="check-name"></span>
	<br />
	<label for="select-cate">Thuộc danh mục : </label>
	<select name="select-category-detail" id="select-category-detail">
		<option value="<?php echo $result[0]['categoryDetailId']; ?>">
			<?php
				$result_cate_first = $sql_util -> getRows('SELECT * FROM categorydetails WHERE categoryDetailId = '.$result[0]['categoryDetailId']);
				echo $result_cate_first[0]['categoryDetailName'];
			?>
		</option>
		<?php
			$result_cate = $sql_util -> getRows('SELECT * FROM categorydetails  WHERE categoryDetailId NOT IN ('.$result[0]['categoryDetailId'].')');
			for ($i=0; $i < count($result_cate); $i++) {
				echo '<option value="'.$result_cate[$i]['categoryDetailId'].'" >'.$result_cate[$i]['categoryDetailName']. '</option>';
			}
		?>
	</select>
	<br />
	<label for="page-numb">Số trang : </label>
	<input type="text" id="page-numb" name="page-numb" value="<?php echo $result[0]['bookPageNumb']; ?>"/>
	<span id="check-page-numb"></span>
	<br />
	<span>Logo : </span>
	<img width="80px" height="115px" src="<?php echo '../images/book/'.$result[0]['bookImage']; ?>" />
	<label for="upload">Thay thế :</label>
	<input type="file" name="upload" id="upload" />
	<span id="check-image"></span>
	<br />
	<label for="select-author">Của tác giả : </label>
	<select name="select-author" id="select-author">
		<option value="<?php echo $result[0]['authorId']; ?>">
			<?php
				$result_cate_first = $sql_util -> getRows('SELECT * FROM authors WHERE authorId = '.$result[0]['authorId']);
				echo $result_cate_first[0]['authorName'];
			?>
		</option>
		<?php
			$result_cate = $sql_util -> getRows('SELECT * FROM authors  WHERE authorId NOT IN ('.$result[0]['authorId'].')');
			for ($i=0; $i < count($result_cate); $i++) {
				echo '<option value="'.$result_cate[$i]['authorId'].'" >'.$result_cate[$i]['authorName']. '</option>';
			}
		?>
	</select>
	<br/>
	<label for="select-publisher">Nhà xuất bản : </label>
	<select name="select-publisher" id="select-publisher">
		<option value="<?php echo $result[0]['publisherId']; ?>">
			<?php
				$result_cate_first = $sql_util -> getRows('SELECT * FROM publishers WHERE publisherId = '.$result[0]['publisherId']);
				echo $result_cate_first[0]['publisherName'];
			?>
		</option>
		<?php
			$result_cate = $sql_util -> getRows('SELECT * FROM publishers  WHERE publisherId NOT IN ('.$result[0]['publisherId'].')');
			for ($i=0; $i < count($result_cate); $i++) {
				echo '<option value="'.$result_cate[$i]['publisherId'].'" >'.$result_cate[$i]['publisherName']. '</option>';
			}
		?>
	</select>
	<br/>
	<label for="select-book-store">Có tại hiệu sách : </label>
	<select name="select-book-store" id="select-book-store">
		<option value="<?php echo $result[0]['bookStoreId']; ?>">
			<?php
				$result_cate_first = $sql_util -> getRows('SELECT * FROM bookstores WHERE bookStoreId = '.$result[0]['bookStoreId']);
				echo $result_cate_first[0]['bookStoreName'];
			?>
		</option>
		<?php
			$result_cate = $sql_util -> getRows('SELECT * FROM bookStores  WHERE bookStoreId NOT IN ('.$result[0]['bookStoreId'].')');
			for ($i=0; $i < count($result_cate); $i++) {
				echo '<option value="'.$result_cate[$i]['bookStoreId'].'" >'.$result_cate[$i]['bookStoreName']. '</option>';
			}
		?>
	</select>
	<br/>
	<label for="size">Cỡ sách : </label>
	<input type="text" name="size" id="size" value="<?php echo $result[0]['bookSize']; ?>" />
	<span id="check-size"></span>
	<br />
	<label for="price">Giá bán : </label>
	<input type="text" name="price" id="price" value="<?php echo $result[0]['bookPrice']; ?>"/>
	<span id="check-price"></span>
	<br />
	<label for="discount">Chiết khấu :</label>
	<input type="text" name="discount" id="discount" value="<?php echo $result[0]['bookDiscount']; ?>" />
	<span id="check-discount"></span>
	<br />
	<label for="description">Giới thiệu :</label>
	<textarea id="description" name="description" rows="10" cols="70"><?php echo $result[0]['bookDescription']; ?></textarea>
	<span id="check-description"></span>
	<br />
	<input type="submit" id="button" name="button" value="Submit"/>
</form>